package org.kfive.nova.io;

import com.google.common.base.Strings;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/*
* ZipUtils.java
* Created  by  dell
* Created on 2016/3/11 17:06
*/
public class ZipUtils {

    public static void zip(String location) throws IllegalArgumentException,FileNotFoundException,IOException{
        //校验文件地址
        if (Strings.isNullOrEmpty(location)){
            throw new IllegalArgumentException("empty location");
        }

        File target = new File(location);

        if(!target.exists()){
            throw new IllegalArgumentException("not exists location");
        }

        FileInputStream inputStream = new FileInputStream(target);


        File zipFile = new File("D:/data.zip");
        if(zipFile.exists()){
            zipFile.delete();
        }
        zipFile.createNewFile();
        FileOutputStream outputStream = new FileOutputStream(zipFile);
        ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
        zipOutputStream.putNextEntry(new ZipEntry(target.getName()));
        int count = 0;
        byte []data = new byte[1024];
        while((count=inputStream.read(data))!=-1){
            zipOutputStream.write(data);
        }
        zipOutputStream.close();
        outputStream.close();
        inputStream.close();
    }

    public static void main(String[] args) {
//        try {
//            ZipUtils.zip("D:/01_0101.dat");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        System.out.print(Long.valueOf(26572809));
    }

}
